const { contextBridge, ipcRenderer } = require('electron')
// 渲染进程


contextBridge.exposeInMainWorld('versions', {
  node: () => process.versions.node,
  chrome: () => process.versions.chrome,
  electron: () => process.versions.electron,
  ping: () => ipcRenderer.invoke('ping'),
  sedMsg: () => ipcRenderer.invoke("msg", {name: 'zs', age:1, sex:1}),
  getProtOne: () => {
    const { port1, port2 } = new MessageChannel();
    return ipcRenderer.postMessage('port', {message:"这是port1的消息"}, [port1])
  },
  openFile: () => ipcRenderer.invoke('openFile'),


  showContextMenu: () => ipcRenderer.send('show-context-menu'),
  contextMenuCommand: () => ipcRenderer.on('context-menu-command', (e, command) => {
    console.log("监听", e, command)
  }),

  getChannel: () => ipcRenderer.on('chanal', (e) => {
    console.log("是否会走到这里")
    e.ports[0].onmessage = (messageEvent) => {
      console.log("消息数据", messageEvent.data)
    }
  }),


  download: () => ipcRenderer.invoke("download"),
  pause: () => ipcRenderer.invoke("pause"),
  unpause: () => ipcRenderer.invoke("unpause"),
})